package cn.lingyangwl.agile.msg.push.controller;

import cn.lingyangwl.agile.msg.push.assembly.*;
import cn.lingyangwl.agile.msg.push.model.entity.*;
import cn.lingyangwl.agile.msg.push.model.rqrs.notice.*;
import cn.lingyangwl.agile.msg.push.service.*;
import cn.lingyangwl.framework.core.response.*;
import cn.lingyangwl.framework.security.xss.core.*;
import cn.lingyangwl.framework.validation.group.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 消息设置
 * 
 * @author shenguangyang
 */
@Api(tags = "消息设置")
@RestController
@RequestMapping("/noticeChannel")
public class NoticeChannelController {
    @Resource
    private NoticeChannelService noticeChannelService;
    @Resource
    private NoticeChannelAssembly noticeChannelAssembly;

    @ApiOperation(value = "通过id查找消息设置")
    @GetMapping("/get")
    public Resp<NoticeChannelResp> getNoticeChannel(@RequestParam(value = "id") Long id) {
        NoticeChannel entity = noticeChannelService.getNoticeChannel(id);
        return Resp.ok(noticeChannelAssembly.toNoticeChannelResp(entity));
    }

    @ApiOperation(value = "保存消息设置")
    @PostMapping("/save")
    @XssCleanIgnore({"content"})
    public Resp<?> saveNoticeChannel(@Validated(InsertGroup.class) @RequestBody NoticeChannelSaveReq req) {
        return Resp.ok(noticeChannelService.saveNoticeChannel(req));
    }

    @ApiOperation(value = "更新消息设置")
    @PostMapping("/update")
    @XssCleanIgnore({"content"})
    public Resp<?> updateNoticeChannel(@Validated(UpdateGroup.class) @RequestBody NoticeChannelSaveReq req) {
        return Resp.ok(noticeChannelService.updateNoticeChannel(req));
    }

    @ApiOperation(value = "获取第三方渠道模板ids")
    @GetMapping(value = "/listTemplateIds")
    public Resp<List<String>> listTemplateIdsByCodes(@RequestParam("noticeCodes") List<String> noticeCodes) {
        return Resp.ok(noticeChannelService.listTemplateIdsByCodes(noticeCodes));
    }

//    @ApiOperation(value = "保存消息设置")
//    @PostMapping("/setting")
//    public Resp<?> settingChannel(@Validated(InsertGroup.class) @RequestBody NoticeChannelSaveReq req) {
//        return Resp.ok(noticeChannelService.saveNoticeChannel(req));
//    }
}
